home *** CD-ROM | disk | FTP | other *** search
- /*
- * NOTICE
- *
- * Copyright 1988, 1989 by h-three Systems Corporation.
- *
- * Permission is hereby granted for this software's free reproduction
- * and modification for non-commercial purposes, provided that this
- * notice is retained. Commercial enterprises may give away copies
- * as part of their products provided that they do so without charge,
- * that they retain this notice, and that they acknowledge the source
- * of the software.
- *
- * PostScript is a registered trademark of Adobe Systems Incorporated.
- * IBM is a registered trademark of International Business Machines
- * Corporation.
- *
- * h-three Systems Corporation
- * 100 Park Drive Suite 204/ P.O. Box 12557
- * Research Triangle Park, NC 27709
- */
-
- /* modified by Bryan Bayerdorffer 4/91. Simplified code by chopping out
- * sysV-isms. */
-
-
-
- /*
- * unfont.c
- *
- * usage: unfont file
- *
- * or
- *
- * unfont reads from stdin
- *
- * Unpacks IBM PC-format PostScript fonts into a downloadable form.
- *
- */
-
- #include <stdio.h>
- #include <fcntl.h>
- #include <ctype.h>
-
- #define OK 0
- #define FAILURE (-1)
- #define Failed(x) ((x) == FAILURE)
- #define TRUE 1
- #define FALSE 0
- typedef char bool;
- #define STREQ(a,b) (strcmp(a,b) == 0)
-
- FILE *fp;
-
- /*
- * used to convert nibbles (n0 is least sig) to ascii-hex
- */
-
- #define N0(c) hexbyt[((c) & 0x000f)]
- #define N1(c) N0((c) >> 4)
-
- char hexbyt[] = "0123456789ABCDEF";
-
- /*
- * vars controlled by command line options
- */
-
- char *infile;
-
- char *progname; /* for error() */
-
- char *strchr(), *strrchr();
-
- int mygetc();
- void dounfont();
- long getcount();
- void bintohex();
-
- main(argc, argv)
- int argc;
- char **argv;
- {
-
- /* unfont stuff */
-
- if (argv[1])
- {
-
- if (!(fp = fopen(argv[1], "r"))) {
- printf("can't open input file '%s'", argv[1]);
- }
-
- infile = argv[1];
- dounfont();
- fclose(fp);
- }
- else
- {
- infile = "<stdin>";
- fp = stdin;
- dounfont();
- }
- exit(0);
- }
-
- long getcount();
-
- void
- dounfont()
- {
- register int c;
- long count;
- register int i;
-
- for (;;)
- {
- if ((c = mygetc()) != 0x80) {
- printf("not a proper font data segment '%s'", infile);
- printf("foobar char is 0x%x", c);
- exit(1);
- }
- c = mygetc();
- switch (c) {
- case 1:
- /* get count, output count bytes to stdout */
- count = getcount();
-
- for (i=0; i<count; i++) {
- c = mygetc();
- putchar(c == '\r' ? '\n' : c);
- }
- break;
- case 2:
- /* get count, convert count bytes to hex, output */
- /* to stdout */
- count = getcount();
-
-
- bintohex(count);
- break;
- case 3:
- /* reached EOF; next file, please */
-
- return;
-
- default:
- printf("not a valid segment type '%s'", infile);
- return;
- }
- }
- }
-
- /*
- * getc for error-checking
- */
-
- int
- mygetc()
- {
- int ch;
- if ((ch = getc(fp)) == -1) {
- printf("unexpected eof on input in '%s'", infile);
- exit(1);
- }
- return(ch);
- }
-
- /*
- * get count of bytes from segment header
- */
-
- long
- getcount()
- {
- int i;
- long count = 0;
-
- for (i=0; i<4; i++)
- count += ((long) mygetc()) << (i * 8);
- return(count);
- }
-
- /*
- * convert binary to ASCII hex and write it to stdout
- */
-
- void
- bintohex(count)
- long count;
- {
- int ch;
- long i;
-
- for (i=0; i<count; i++) {
- if ((i % 30) == 0)
- putchar('\n');
- ch = mygetc();
- putchar(N1(ch));
- putchar(N0(ch));
- }
- }
-